<?
$sub_menu = "400400";
include_once("./_common.php");
include_once("$g4[path]/lib/shop.lib.php");
auth_check($auth[$sub_menu], "r");
$g4[title] = "매출리포트";
include_once("./admin.head.php");

if(!$Year || $Year==""){$Year = date("Y");}
if(!$Month || $Month==""){$Month = date("m");}

$maxDate = date("t",strtotime($Year."-".$Month."-01"));

$sql = "select * from g4_order where 1 and (buy_datetime >= '".date("Y-m-d",strtotime($Year."-".$Month."-01"))." 00:00:00' and buy_datetime <= '".date("Y-m-d",strtotime($Year."-".$Month."-".$maxDate))." 23:59:59')";
$rst = mysql_query($sql);
//$order_list = array(array());

while($row = mysql_fetch_array($rst))
{
	$tmp_date = explode("-",str_replace("-0","-",substr($row[buy_datetime],0,10)));


	$order_list[$tmp_date[1]][$tmp_date[2]][$row[status]][pay_price]+= $row[pay_price];
	$order_list[$tmp_date[1]][$tmp_date[2]][$row[status]][pay_tranc]+= $row[pay_tranc];
	$order_list[$tmp_date[1]][$tmp_date[2]][$row[status]][pay_point]+= $row[pay_point];
	$order_list[$tmp_date[1]][$tmp_date[2]][$row[status]][pay_amount]+= $row[pay_amount];

	$order_list[$tmp_date[1]][$tmp_date[2]][$row[status]][cnt]++;

}
?>
<style>
.list_price{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#666666}
.list_tranc{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#FF66FF}
.list_point{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#6666FF}
.list_amount{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#FF6666}
.row_list_price{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#000000}
.row_list_tranc{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#FF00FF}
.row_list_point{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#0000FF}
.row_list_amount{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#FF0000}
.col_list_price{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#999999}
.col_list_tranc{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#660099}
.col_list_point{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#000099}
.col_list_amount{font-family:돋움;font-size:11px;width:100%;text-align:right;color:#990000}

.tot_price{font-family:돋움;font-size:11px;width:100;text-align:right;background:#000000;color:#FFFFFF}
.tot_tranc{font-family:돋움;font-size:11px;width:100;text-align:right;background:#660099;color:#FFFFFF}
.tot_point{font-family:돋움;font-size:11px;width:100;text-align:right;background:#000099;color:#FFFFFF}
.tot_amount{font-family:돋움;font-size:11px;width:100;text-align:right;background:#990000;color:#FFFFFF}

.index_date{font-family:돋움;font-size:11px;color:#000000}

#order_report td{border-right:solid 1px #CCCCCC;border-bottom:solid 1px #CCCCCC}
#order_report{border-left:solid 1px #CCCCCC;border-top:solid 1px #CCCCCC;}
</style>
<form name="reportFrm" method="post">
조회기간 : 
<input type="text" class="ed" style="width:40px" name="Year" value="<?=$Year?>">년
<input type="text" class="ed" style="width:30px" name="Month" value="<?=$Month?>">월
<button class="btn1" onclick="submit();">조회</button>
</form>
<span style="color:#000000">■</span>상품총액
<span style="color:#FF00FF">■</span>배송비
<span style="color:#0000FF">■</span>포인트결제
<span style="color:#FF0000">■</span>실결제액
<table cellpadding="2" cellspacing="0" border="0" id="order_report">
	<colgroup>
	<col width="40">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	<col width="70">
	</colgroup>
	<tr align="center">
		<td>날짜</td>
		<?for($i=0;$i<=8;$i++){?>
		<td><?=get_status($i)?></td>
		<?}?>
		<td>일합계</td>
	</tr>
	<?

	$subMonth = $Month > 9 ? $Month : substr($Month,1,1);
	for($j=1;$j<=$maxDate;$j++)
	{
	?>
	<tr align="right">
		<td align="center"><span class="index_date"><?=date("m-d",strtotime($Year."-".$Month."-".$j))?></span></td>
		<?
		for($i=0;$i<=8;$i++)
		{

		$row_list[$subMonth][$j][tot_amount]+= $order_list[$subMonth][$j][$i][pay_amount];
		$row_list[$subMonth][$j][tot_tranc]+= $order_list[$subMonth][$j][$i][pay_tranc];
		$row_list[$subMonth][$j][tot_point]+= $order_list[$subMonth][$j][$i][pay_point];
		$row_list[$subMonth][$j][tot_price]+= $order_list[$subMonth][$j][$i][pay_price];
		$row_list[$subMonth][$j][cnt]+= $order_list[$subMonth][$j][$i][cnt];

		$col_list[$i][total_price]+=$order_list[$subMonth][$j][$i][pay_price];
		$col_list[$i][total_tranc]+=$order_list[$subMonth][$j][$i][pay_tranc];
		$col_list[$i][total_point]+=$order_list[$subMonth][$j][$i][pay_point];
		$col_list[$i][total_amount]+=$order_list[$subMonth][$j][$i][pay_amount];
		$col_list[$i][cnt]+=$order_list[$subMonth][$j][$i][cnt];

		?>
		<td onmouseover="this.style.background='#FFEFEF'" onmouseout="this.style.background='#FFFFFF'" style="cursor:pointer" onclick="location.href='./order_list.php?startDate=<?=date("Ymd",strtotime($Year."-".$Month."-".$j))?>&endDate=<?=date("Ymd",strtotime($Year."-".$Month."-".$j))?>&status=<?="S".$i?>';" title="판매건수 : <?=number_format($order_list[$subMonth][$j][$i][cnt])?>건">
		<span class="list_price"><?=number_format($order_list[$subMonth][$j][$i][pay_price])?>원</span><br>
		<span class="list_tranc"><?=number_format($order_list[$subMonth][$j][$i][pay_tranc])?>원</span><br>
		<span class="list_point"><?=number_format($order_list[$subMonth][$j][$i][pay_point])?>원</span><br>
		<span class="list_amount"><?=number_format($order_list[$subMonth][$j][$i][pay_amount])?>원</span>
		</td>
		<?}?>
		<td style="cursor:pointer" onclick="location.href='./order_list.php?startDate=<?=date("Ymd",strtotime($Year."-".$Month."-".$j))?>&endDate=<?=date("Ymd",strtotime($Year."-".$Month."-".$j))?>&status=';" title="판매건수 : <?=number_format($row_list[$subMonth][$j][cnt])?>건">
		<span class="row_list_price"><?=number_format($row_list[$subMonth][$j][tot_price])?>원</span><br>
		<span class="row_list_tranc"><?=number_format($row_list[$subMonth][$j][tot_tranc])?>원</span><br>
		<span class="row_list_point"><?=number_format($row_list[$subMonth][$j][tot_point])?>원</span><br>
		<span class="row_list_amount"><?=number_format($row_list[$subMonth][$j][tot_amount])?>원</span>
		</td>
	</tr>
	<?
	}
	?>
	<tr align="center">
		<td rowspan="2">합계</td>
		<?for($i=0;$i<=8;$i++){?>
		<td><?=get_status($i)?></td>
		<?}?>
		<td>총합계</td>
	</tr>
	<tr align="right">

	<?
	$list_total = array();
	for($i=0;$i<=8;$i++)
	{
	?>
		<td style="cursor:pointer" onclick="location.href='./order_list.php?startDate=<?=date("Ymd",strtotime($Year."-".$Month."-01"))?>&endDate=<?=date("Ymd",strtotime($Year."-".$Month."-".$maxDate))?>&status=<?="S".$i?>';" title="판매건수 : <?=number_format($col_list[$i][cnt])?>건">
		<span class="col_list_price"><?=number_format($col_list[$i][total_price])?>원</span><br>
		<span class="col_list_tranc"><?=number_format($col_list[$i][total_tranc])?>원</span><br>
		<span class="col_list_point"><?=number_format($col_list[$i][total_point])?>원</span><br>
		<span class="col_list_amount"><?=number_format($col_list[$i][total_amount])?>원</span>
		</td>
	<?
		$list_total[price]+=$col_list[$i][total_price];
		$list_total[tranc]+=$col_list[$i][total_tranc];
		$list_total[point]+=$col_list[$i][total_point];
		$list_total[amount]+=$col_list[$i][total_amount];
		$list_total[cnt]+=$col_list[$i][cnt];
	}
	?>
		<td style="cursor:pointer" onclick="location.href='./order_list.php?startDate=<?=date("Ymd",strtotime($Year."-".$Month."-01"))?>&endDate=<?=date("Ymd",strtotime($Year."-".$Month."-".$maxDate))?>&status=';" title="판매건수 : <?=number_format($list_total[cnt])?>건">
		<span class="tot_price"><?=number_format($list_total[price])?>원</span>
		<span class="tot_tranc"><?=number_format($list_total[tranc])?>원</span>
		<span class="tot_point"><?=number_format($list_total[point])?>원</span>
		<span class="tot_amount"><?=number_format($list_total[amount])?>원</span>
		</td>
	</tr>
</table>
<?
include_once ("./admin.tail.php");
?>